import java.io.FileOutputStream;
import java.io.IOException;

import com.mongodb.*;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.bson.Document;

public class 控股参股分公司导出 {
	public static void main(String[] args) throws IOException{
		String path="D:\\测试临时文件\\Choice参控股公司2018_结果.xlsx";
		FileOutputStream fos=new FileOutputStream(path);
		Workbook wwb=new SXSSFWorkbook(1000);
		Sheet sheet=wwb.createSheet("sheet");
		int idNO=0;
		int final_line=0;


		MongoClient mongoClient_t=new MongoClient("192.168.1.171",30000);
		MongoCollection<Document> collection = mongoClient_t.getDatabase("Choice_ccg").getCollection("choice_konggucangufengongsi_2021");
		FindIterable<Document> documents=collection.find(new Document("_id",new Document("$gt",""))).sort(new Document("_id",1));
		int line=1;
		for(Document document:documents) {
			//if (line > 10) break;
			System.out.println("读取第---"+(line++)+"---行数据"+document.getString("_id"));
			String id=document.getString("_id");
			Document data= (Document) document.get("data");
			for(int i=0;i<data.size();i++) {
				Document detail= (Document) data.get(String.valueOf(i));
				System.out.println(detail.getString("BHCompName"));
				Row row_i=sheet.createRow(final_line++);
				row_i.createCell(0).setCellValue(id);
				row_i.createCell(1).setCellValue(detail.getString("BHCompName"));
				row_i.createCell(2).setCellValue(detail.getString("HoldingType"));
				row_i.createCell(3).setCellValue(detail.getString("Dec_AinvestMent"));
				row_i.createCell(4).setCellValue(detail.getString("Dec_AinvestMent"));
				row_i.createCell(5).setCellValue(detail.getString("SharehdRatio"));
				row_i.createCell(6).setCellValue(detail.getString("VsharehdRatio"));
				row_i.createCell(7).setCellValue(detail.getString("Dec_Regcapital"));
				row_i.createCell(8).setCellValue(detail.getString("RegAddress"));
				row_i.createCell(9).setCellValue(detail.getString("Operatereve"));
				row_i.createCell(10).setCellValue(detail.getString("Netprofit"));
				row_i.createCell(11).setCellValue(detail.getString("NaBusiness"));
				row_i.createCell(12).setCellValue(detail.getString("IsCombine"));
				row_i.createCell(13).setCellValue(detail.getString("IsNewSanban"));
				row_i.createCell(14).setCellValue(detail.getString("STR_CURRENCY"));
				row_i.createCell(15).setCellValue((i+1)+"");


			}
		}




		wwb.write(fos);
		fos.close();
		
		
		
	}

}
